﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;

namespace LogLib
{
    public class LogOption
    {
        /// <summary>
        /// 系统日志文件保存路径
        /// </summary>
        public string BaseDirectory
        {
            set;
            get;
        } = @"D:\Log\";

        public LogOption()
        {
            BaseDirectory = @"D:\Log";
        }

        public void SetDefaultBaseDirectory()
        {
            string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
            directory = directory.Substring(6);
            BaseDirectory = directory + "/logfile";
            if (!Directory.Exists(BaseDirectory))
            {
                try
                {
                    Directory.CreateDirectory(BaseDirectory);
                    Console.WriteLine($"创建目录{BaseDirectory}成功.");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("试图创建目录{0}失败，原因: {1}.\n请检查配置文件的配置是否正确.", BaseDirectory, ex.Message);
                }
            }
        }
    }
}
